<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {
	
	private $tab = 'platform';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	

	
	
	private function post_data(){
				
		$data = array(
			'parent_id'=>$this->input->post('parent_id'),
			'title'=>$this->input->post('title'),
			'url'=>$this->input->post('url'),
			'type_set'=>$this->input->post('type_set'),
			'forder'=>$this->input->post('forder'),
			'content'=>trim($this->input->post('content')),
			);
		  		
		if($data['title'] == ''){
			$ret['msg'] = '分类名称不能为空';
		}elseif($data['url'] == ''){
			$ret['msg'] = 'URL不能为空';
		}elseif($data['type_set'] == 0 && $data['parent_id'] > 0){
			if($data['content'] == ''){
				$ret['msg'] = '内容编辑不能为空';	
			}
		}
		
		$this->load->model('Site_model');
		$udata['url'] = $data['url'];		
		$sitefinfo = $this->Site_model->get_site_one($udata);
		
		if(intval($this->input->post('id'))>0){
			if($sitefinfo['id'] != intval($this->input->post('id'))){
				$ret['msg'] = 'URL不能重复';	
			}
		}else{
			if($sitefinfo){
				$ret['msg'] = 'URL不能重复';	
			}
		}
		
		
		
		
			
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
  		
  		return $data;
	}
	
	function add_view(){
		$this->load->model('Site_model');
		$this->load->helper(array('form'));
		$vdata['site_array'] = $this->Site_model->get_site_select_array();
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
		$this->load->view("/sys_admin/site/site_add",$vdata);
	}
	
	function add(){
		$data = $this->post_data();
  		$data['add_time'] 	= time();
  		$data['addip'] 	= $this->js->get_ip();
  		
  		$this->load->model('Site_model');
  		$site_id = $this->Site_model->add($data);
  		
		$this->load->model('log_model');
		$this->log_model->add_log('[添加][类别管理]['.$this->input->post('title').']');
   		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	function view($site_id){
		$this->load->model('Site_model');
  		$site = $this->Site_model->get_site_obj($site_id);
  		$vdata['site'] = $site;
  		$this->load->view("/sys_admin/site/site_view", $vdata);
	}
	
	function edit_view($site_id){
		$this->load->helper(array('form'));
		$this->load->model('Site_model');
  		$site = $this->Site_model->get_site_obj($site_id);
  		$vdata['site'] = $site;
  		$vdata['site_array'] = $this->Site_model->get_site_select_array();
  		
  		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
  		$this->load->view("/sys_admin/site/site_edit", $vdata);
	}
	
	function edit(){
		$id 		= $this->input->post('id');
		
		$data = $this->post_data();
		
  		$this->load->model('Site_model');
  		$site_id = $this->Site_model->update($id, $data);
  		
		$this->load->model('log_model');
		$this->log_model->add_log('[修改][类别管理]['.$this->input->post('title').']'.'ID=='.$id);
		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	function zhs_sitelist(){
		//接收参数
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$pid 			= $this->input->get('parent_id');
		
		$data = array();
		
		if($pid != ''){
			$data['where']['parent_id'] = $pid;
		}
		
		
		$data['page_size'] = 10;
		$data['page_start'] = $per_page;
		
		$this->load->model('Site_model');
		$vdata = $this->Site_model->get_site_category_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/site/zhs_sitelist/?title='.$title.'&fgroup='.$fgroup;
		$config['total_rows'] = $vdata['site_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['title'] 	= $title;
		$vdata['pid'] 	= $pid;
		$vdata['url'] 		= $url;
		//$vdata['group_list']= $this->Site_model->get_fgroup();
		$vdata['site_array'] = $this->Site_model->get_site_select_parent_array();
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
		$this->load->view('/sys_admin/site/site_list', $vdata);
	}
	
	function remove(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('Site_model');
  		$this->load->model('log_model');$this->log_model->add_log('[删除][类别管理]');
		echo  $this->Site_model->update($id, $data);
	}
	
}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {
    
	private $tab = 'platform';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	

	
	
	private function post_data(){
				
		$data = array(
			'parent_id'=>$this->input->post('parent_id'),
			'title'=>$this->input->post('title'),
			'url'=>$this->input->post('url'),
			'type_set'=>$this->input->post('type_set'),
			'forder'=>$this->input->post('forder'),
			'content'=>trim($this->input->post('content')),
			);
		  		
		if($data['title'] == ''){
			$ret['msg'] = '分类名称不能为空';
		}elseif($data['url'] == ''){
			$ret['msg'] = 'URL不能为空';
		}elseif($data['type_set'] == 0 && $data['parent_id'] > 0){
			if($data['content'] == ''){
				$ret['msg'] = '内容编辑不能为空';	
			}
		}
		
		$this->load->model('Site_model');
		$udata['url'] = $data['url'];		
		$sitefinfo = $this->Site_model->get_site_one($udata);
		
		if(intval($this->input->post('id'))>0){
			if($sitefinfo['id'] != intval($this->input->post('id'))){
				$ret['msg'] = 'URL不能重复';	
			}
		}else{
			if($sitefinfo){
				$ret['msg'] = 'URL不能重复';	
			}
		}
		
		
		
		
			
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
  		
  		return $data;
	}
	
	function add_view(){
		$this->load->model('Site_model');
		$this->load->helper(array('form'));
		$vdata['site_array'] = $this->Site_model->get_site_select_array();
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
		$this->load->view("/sys_admin/site/site_add",$vdata);
	}
	
	function add(){
		$data = $this->post_data();
  		$data['add_time'] 	= time();
  		$data['addip'] 	= $this->js->get_ip();
  		
  		$this->load->model('Site_model');
  		$site_id = $this->Site_model->add($data);
  		
		$this->load->model('log_model');
		$this->log_model->add_log('[添加][类别管理]['.$this->input->post('title').']');
   		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	function view($site_id){
		$this->load->model('Site_model');
  		$site = $this->Site_model->get_site_obj($site_id);
  		$vdata['site'] = $site;
  		$this->load->view("/sys_admin/site/site_view", $vdata);
	}
	
	function edit_view($site_id){
		$this->load->helper(array('form'));
		$this->load->model('Site_model');
  		$site = $this->Site_model->get_site_obj($site_id);
  		$vdata['site'] = $site;
  		$vdata['site_array'] = $this->Site_model->get_site_select_array();
  		
  		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
  		$this->load->view("/sys_admin/site/site_edit", $vdata);
	}
	
	function edit(){
		$id 		= $this->input->post('id');
		
		$data = $this->post_data();
		
  		$this->load->model('Site_model');
  		$site_id = $this->Site_model->update($id, $data);
  		
		$this->load->model('log_model');
		$this->log_model->add_log('[修改][类别管理]['.$this->input->post('title').']'.'ID=='.$id);
		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	function zhs_sitelist(){
		//接收参数
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$pid 			= $this->input->get('parent_id');
		
		$data = array();
		
		if($pid != ''){
			$data['where']['parent_id'] = $pid;
		}
		
		
		$data['page_size'] = 10;
		$data['page_start'] = $per_page;
		
		$this->load->model('Site_model');
		$vdata = $this->Site_model->get_site_category_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/site/zhs_sitelist/?title='.$title.'&fgroup='.$fgroup;
		$config['total_rows'] = $vdata['site_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['title'] 	= $title;
		$vdata['pid'] 	= $pid;
		$vdata['url'] 		= $url;
		//$vdata['group_list']= $this->Site_model->get_fgroup();
		$vdata['site_array'] = $this->Site_model->get_site_select_parent_array();
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'site_article';
		
		$this->load->view('/sys_admin/site/site_list', $vdata);
	}
	
	function remove(){
		$id 				= $this->input->post('id');
  		$data["is_del"]		= 1;
  		$this->load->model('Site_model');
  		$this->load->model('log_model');$this->log_model->add_log('[删除][类别管理]');
		echo  $this->Site_model->update($id, $data);
	}
	
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
